<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>预约接种记录</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style>
        body{
            margin-top: 0;
            padding: 30px;
        }
    </style>
</head>
<body>
<ol class="breadcrumb">
    <li><a href="/mainbg">主页</a></li>
    <li><a href="#">预约接种管理</a></li>
</ol>
<div id="pointInfo" class="container-fluid">
    <input id="userId" th:value="${session.user.id}" type="hidden">
    <div class="panel panel-success">
        <div class="panel-heading">接种疫苗预约记录</div>
        <input type="hidden" name="pageNo" id="pageNo" th:value="${pageInfo.pageNum}" >
        <input type="hidden" name="pageSize" id="pageSize" th:value="${pageInfo.pageSize}">
        <input type="hidden" id="pageTotal" th:value="${pageInfo.total}">
        <table class="table table-bordered table-striped table-hover" style="margin-top: 10px">
            <thead>
                <tr class="info">
                    <th>编号</th>
                    <th>疫苗名称</th>
                    <th>接种点名称</th>
                    <th>预约时间</th>
                    <th>开始接种时间</th>
                    <th>结束接种时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            <tr th:if="${reservationList.size()==0||reservationList==null}">
                <td colspan="7" style="text-align: center;font-size: 18px;color: red">暂无预约记录</td>
            </tr>
                <tr th:each="reservation:${reservationList}">
                    <td th:text="${reservation.id}"></td>
                    <td th:text="${reservation.vaccinesname}"></td>
                    <td th:text="${reservation.inoculationname}"></td>
                    <td th:text="${#dates.format(reservation.reservationtime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    <td th:text="${#dates.format(reservation.starttime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    <td th:text="${#dates.format(reservation.endtime, 'yyyy-MM-dd HH:mm:ss')}"></td>
                    <td>
                        <span th:if="${reservation.status==0}">
                            <button type="button" class="btn btn-success btn-sm" disabled>
                                <span class="glyphicon glyphicon-ok">已完成</span></button>
                        </span>
                        <span th:if="${reservation.status==1}">
                            <button type="button" class="btn btn-warning btn-sm" th:onclick="addInoculationHistory('[[${reservation}]]')">
                                <span class="glyphicon glyphicon-ok">接种完毕</span></button>
                            <button type="button" class="btn btn-danger btn-sm" th:onclick="cancelRese('[[${reservation}]]')">
                                <span class="glyphicon glyphicon-remove">取消预约</span></button>
                        </span>
                        <span th:if="${reservation.status==2}">
                            <button type="button" class="btn btn-info btn-sm" disabled>
                                <span class="glyphicon glyphicon-ok">已取消</span></button>
                        </span>
                    </td>
                </tr>
            </tbody>
        </table>
        <div id="pageDemo"></div>
    </div>
</div>
<script type="text/javascript" src="js/layuiDateForMate.js"></script>
<script type="text/javascript">
    function timeOutReflush() {
        setTimeout(function () {
            window.location.href='findAllReservationHist?pageNo='+$('#pageNo').val()+'&pageSize='+$('#pageSize').val();
        },1500);
    }
    function addInoculationHistory(reservation) {
        console.log(reservation);
        var reservation=eval("("+reservation+")");   //将json转化成对象
        console.log(typeof reservation);
        $.ajax({
            url: '/addInoculationHistory',
            type: 'post',
            data: {
                "id":reservation.id,
                "userid":$("#userId").val(),
                "vaccinesid":reservation.vaccinesid,
                "inoculationid":reservation.inoculationid
            },
            success: function (result) {
                console.log(result);
                if(result=='SUCCESS'){   //修改成功
                    layer.msg("操作成功",{icon:1});
                    timeOutReflush();
                }else{   //登录失败
                    layer.alert('操作失败!',{icon:2});
                }
            }
        });
        return false;
    }
    function cancelRese(reservation) {
        console.log(reservation);
        var reservation=eval("("+reservation+")");   //将json转化成对象
        console.log(typeof reservation);
        $.ajax({
            url: '/cancelRese',
            type: 'post',
            data: {
                "id":reservation.id,
                "userid":$("#userId").val(),
                "vaccinesid":reservation.vaccinesid,
                "inoculationid":reservation.inoculationid
            },
            success: function (result) {
                console.log(result);
                if(result=='SUCCESS'){   //修改成功
                    layer.msg("操作成功",{icon:1});
                    timeOutReflush();
                }else{   //登录失败
                    layer.alert('操作失败!',{icon:2});
                }
            }
        });
        return false;
    }
</script>
<script type="text/javascript">
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        var form = layui.form;
        var layer = layui.layer;
        var util = layui.util;

        let pageNo=parseInt($('#pageNo').val());
        let pageSize=parseInt($('#pageSize').val());
        let pageTotal=parseInt($('#pageTotal').val());

        //完整功能
        laypage.render({
            elem: 'pageDemo'
            ,count: pageTotal
            ,curr: pageNo
            ,limit: pageSize
            ,limits: [5,10,20,30,50]
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,jump: function(obj,first){
                console.log(obj);
                if(!first){
                    //do something
                    /*$('#pageNo').val(obj.curr);
                    $('#pageSize').val(obj.limit);
                    $('#searchForm').submit();*/
                    console.log("pageNo="+obj.curr+",pageSize="+obj.limit);
                    location.href="findAllReservationHist?pageNo="+obj.curr+"&pageSize="+obj.limit;
                }
            }
        });
    });
</script>
</body>
</html>